package com.qk.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qk.common.PageResult;
import com.qk.dto.CustomerDto;
import com.qk.entity.Customer;
import com.qk.mapper.CustomerMapper;
import com.qk.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    //客户列表查询
    @Override
    public PageResult<Customer> list(CustomerDto customerDto) {
        log.info("查询客户列表  " + customerDto);
        Page<Customer> page = customerMapper.listCustomers(new Page<Customer>(customerDto.getPage(), customerDto.getPageSize()), customerDto);
        return new PageResult<>(page.getTotal(), page.getRecords());

    }
    //新增客户
    @Override
    public void add(Customer customer) {
        log.info("新增客户  " + customer);
        customerMapper.insert(customer);
    }

    //根据ID查询客户信息
    @Override
    public Customer getById(Integer id) {
        log.info("查询客户信息  " + id);
        return customerMapper.selectById( id);
    }

    //修改客户信息
    @Override
    public void update(Customer customer) {
        log.info("修改客户信息  " + customer);
        customerMapper.updateById(customer);

    }
}
